Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend-native): Handle closed channel on Rust side #9242

Merged
merged 1 commit into from
Feb 20, 2025

Conversation

mcheshkov
Copy link
Member

@mcheshkov mcheshkov commented Feb 19, 2025

Check List

  • Tests have been run in packages where changes made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Description of Changes Made (if issue reference is not provided)

DataFusion can execute complex queries, containing multiple CubeScans, specifically multiple CubeScanExecutionPlan in physical plan
CubeScanExecutionPlans can be executed concurrently, and as such concurrently trigger load calls on TransportService
Then, if one of several concurrent calls receives error whole stream with still-executing-plans can be dropped
For NodeBridgeTransport this would lead to dropping receiver side in call_raw_js_with_channel_as_callback
But sender side would continue to live in JS thread
Then JS side can call writerOrChannel.resolve, and it would find that channel is closed, and raise exception
But then this exception will be caught, leading to writerOrChannel.reject call
And because writerOrChannel.resolve already consumed channel it would raise its own exception
And, because wrapNativeFunctionWithStream uses async function, this exception would lead to promise rejection, will not get caught in native part on JS side (it does not care for return values), and can trigger unhandled rejection

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.57%. Comparing base (511ca8a) to head (066787a).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9242   +/-   ##
=======================================
  Coverage   83.56%   83.57%           
=======================================
  Files         227      227           
  Lines       81618    81618           
=======================================
+ Hits        68206    68210    +4     
+ Misses      13412    13408    -4     
Flag Coverage Δ
cubesql 83.57% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mcheshkov mcheshkov marked this pull request as ready for review February 19, 2025 16:58
@mcheshkov mcheshkov requested a review from a team as a code owner February 19, 2025 16:58
Copy link
Member

@KSDaemon KSDaemon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

DataFusion can execute complex queries, containing multiple CubeScans, specifically multiple `CubeScanExecutionPlan` in physical plan
`CubeScanExecutionPlan`s can be executed concurrently, and as such concurrently trigger load calls on `TransportService`
Then, if one of several concurrent calls receives error whole stream with still-executing-plans can be dropped
For `NodeBridgeTransport` this would lead to dropping receiver side in `call_raw_js_with_channel_as_callback`
But sender side would continue to live in JS thread
Then JS side can call `writerOrChannel.resolve`, and it would find that channel is closed, and raise exception
But then this exception will be caught, leading to `writerOrChannel.reject` call
And because `writerOrChannel.resolve` already consumed channel it would raise its own exception
And, because `wrapNativeFunctionWithStream` uses async function, this exception would lead to promise rejection, will not get caught in native part on JS side (it does not care for return values), and can trigger unhandled rejection
@mcheshkov mcheshkov force-pushed the native-backend-channel-drop branch from 2d0e4c6 to 066787a Compare February 20, 2025 11:25
@mcheshkov mcheshkov merged commit 1203291 into master Feb 20, 2025
83 checks passed
@mcheshkov mcheshkov deleted the native-backend-channel-drop branch February 20, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants